package com.webermagem.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name="TB_INTERVENCOES")
public class Intervencao {
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)  
    @Column(name = "id", nullable = false, unique = true)
	private long id;
	
	private String descricao;

	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name = "TB_SINT_DIAG", joinColumns = {@JoinColumn(name="id_intervencao") },	inverseJoinColumns = {@JoinColumn(name="id_diagnostico")}	)
	private Set<Diagnostico> dignosticos;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public Set<Diagnostico> getDignosticos() {
		return dignosticos;
	}

	public void setDignosticos(Set<Diagnostico> dignosticos) {
		this.dignosticos = dignosticos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((descricao == null) ? 0 : descricao.hashCode());
		result = prime * result
				+ ((dignosticos == null) ? 0 : dignosticos.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Intervencao other = (Intervencao) obj;
		if (descricao == null) {
			if (other.descricao != null)
				return false;
		} else if (!descricao.equals(other.descricao))
			return false;
		if (dignosticos == null) {
			if (other.dignosticos != null)
				return false;
		} else if (!dignosticos.equals(other.dignosticos))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	public Intervencao(){
		
	}

}
